package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.service.IProcesstypeDescService;
import org.hibernate.validator.constraints.EAN;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.LeaveApply;
import com.stylefeng.guns.modular.system.service.ILeaveApplyService;

/**
 * 请假申请控制器
 *
 * @author fengshuonan
 * @Date 2019-06-21 08:54:00
 */
@Controller
@RequestMapping("/leaveApply")
public class LeaveApplyController extends BaseController {

    private String PREFIX = "/system/leaveApply/";

    @Autowired
    private ILeaveApplyService leaveApplyService;

    @Autowired
    private IProcesstypeDescService processtypeDescService;

    /**
     * 跳转到请假申请首页
     */
    @RequestMapping("/leave_apply")
    public String index() {
        return PREFIX + "leaveApply.html";
    }

    /**
     * 跳转到添加请假申请
     */
    @RequestMapping("/leaveApply_add")
    public String leaveApplyAdd(Model model) {
        model.addAttribute("userId",ShiroKit.getUser().getId());
        return PREFIX + "leaveApply_add.html";
    }

    /**
     * 跳转到修改请假申请
     */
    @RequestMapping("/leaveApply_update/{leaveApplyId}")
    public String leaveApplyUpdate(@PathVariable Integer leaveApplyId, Model model) {
        LeaveApply leaveApply = leaveApplyService.selectById(leaveApplyId);
        model.addAttribute("item",leaveApply);
        LogObjectHolder.me().set(leaveApply);
        return PREFIX + "leaveApply_edit.html";
    }

    /**
     * 获取请假申请列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        //a
        return leaveApplyService.selectList(null);
    }

    /**
     * 新增请假申请
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LeaveApply leaveApply,Model model) {
        leaveApplyService.insert(leaveApply);
        /*Integer userId = ShiroKit.getUser().getId();*/

        return SUCCESS_TIP;
    }

    /**
     * 删除请假申请
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer leaveApplyId) {
        leaveApplyService.deleteById(leaveApplyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改请假申请
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LeaveApply leaveApply) {
        leaveApplyService.updateById(leaveApply);
        return SUCCESS_TIP;
    }

    /**
     * 添加
     */
    /**
     * 修改请假申请
     */
    @RequestMapping(value = "/findName")
    @ResponseBody
    public Object findName(LeaveApply leaveApply,Integer id) {
        /*leaveApplyService.findName();*/
        return leaveApplyService.findName();
    }

    /**
     * 请假申请详情
     */
    @RequestMapping(value = "/detail/{leaveApplyId}")
    @ResponseBody
    public Object detail(@PathVariable("leaveApplyId") Integer leaveApplyId) {
        return leaveApplyService.selectById(leaveApplyId);
    }
}
